-
Notifications
You must be signed in to change notification settings - Fork 42
Fixing Parent ID #235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing Parent ID #235
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughRemoved all augmentation of state.parents with the current state's own identifier across execution paths. New and existing states now retain the original parents mapping without adding a self-referential entry. Control flow, function signatures, background tasks, and error handling remain unchanged. Changes
Sequence Diagram(s)Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @NiveditJain, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request addresses a bug where the parents field of a state object was being incorrectly updated to include the state's own ID, leading to self-referential parent relationships. The changes remove the erroneous logic that added the current state's ID to its parents dictionary during state execution and ensure that subsequent state creations correctly inherit the existing parent relationships without modification. This fix resolves an issue related to accurate parent ID handling within the state management system.
Highlights
- Corrected Parent ID Assignment: The logic that incorrectly added the current state's ID to its own
parentsdictionary within theexecuted_statefunction has been removed. This was occurring both whenbody.outputswas empty and when it contained data. - Refined State Creation with Parent Inheritance: The
create_next_statefunction now correctly passes the existingstate.parentsto new states, ensuring that parent relationships are maintained without self-referencing the current state as its own parent.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request aims to fix an issue with parent ID assignment for states. The changes correctly prevent a state from being assigned as its own parent and properly set the parentage for new states created from multiple outputs, treating them as siblings. While the logic of the fix seems correct, the corresponding unit tests have not been updated to include assertions for the parents field, which is a significant omission for a change of this nature. Additionally, I've identified some code duplication that could be refactored for better maintainability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (5)
state-manager/app/controller/executed_state.py (5)
31-31: Pass identifiers to background tasks instead of full document instancesHanding a full
Statedocument toBackgroundTaskscan introduce stale-data issues, heavier memory usage, and accidental coupling. Prefer passingstate.id(and re-fetch inside the task), which also lets you drop the extra read afterinsert_many.Apply this diff (if
create_next_statesupports fetching by id):- background_tasks.add_task(create_next_state, state) + background_tasks.add_task(create_next_state, state.id)- background_tasks.add_task(create_next_state, state) + background_tasks.add_task(create_next_state, state.id)- for inserted_state in inserted_states: - background_tasks.add_task(create_next_state, inserted_state) + for inserted_state in inserted_states: + background_tasks.add_task(create_next_state, inserted_state.id)If
create_next_statecurrently expects aStateinstance, I can provide a companion patch to refactor it to accept an id and perform a fresh lookup.Also applies to: 38-38, 66-66
55-63: Skip re-query when scheduling background work (paired with id-passing)If you switch to passing
ids to the background task, you can avoid the extrafind(In(State.id, inserted_ids))round-trip altogether, scheduling tasks directly frominserted_ids.Proposed adjustment:
- if len(new_states) > 0: - inserted_ids = (await State.insert_many(new_states)).inserted_ids - - inserted_states = await State.find( - In(State.id, inserted_ids) - ).to_list() - - if len(inserted_states) != len(new_states): - raise RuntimeError(f"Failed to insert all new states. Expected {len(new_states)} states, but only {len(inserted_states)} were inserted") - - for inserted_state in inserted_states: - background_tasks.add_task(create_next_state, inserted_state) + if new_states: + inserted_ids = (await State.insert_many(new_states)).inserted_ids + if len(inserted_ids or []) != len(new_states): + raise RuntimeError(f"Failed to insert all new states. Expected {len(new_states)} states, but only {len(inserted_ids or [])} were inserted") + for inserted_id in inserted_ids: + background_tasks.add_task(create_next_state, inserted_id)
26-39: Reduce duplication between empty/non-empty outputs branchesBoth branches set
status=EXECUTED, save, and enqueuecreate_next_state. Consider consolidating to reduce duplication and potential drift.High-level idea:
- Compute
outputs = body.outputs[0] if body.outputs else {}- Set
state.outputs = outputs,state.status = EXECUTED- Save once, add one background task
- Then handle
body.outputs[1:]for additional statesI can provide a concrete patch if you’d like.
70-72: Preserve traceback: use bare raise and log exception with stack
raise ecan obscure the original traceback context. Preferraiseto rethrow the same exception and use an exception-aware logger to include the stack trace.Apply this diff:
- except Exception as e: - logger.error(f"Error executing state {state_id} for namespace {namespace_name}", x_exosphere_request_id=x_exosphere_request_id, error=e) - raise e + except Exception as e: + logger.exception(f"Error executing state {state_id} for namespace {namespace_name}", x_exosphere_request_id=x_exosphere_request_id, error=e) + raiseIf
LogsManagerlacksexception, uselogger.error(..., exc_info=True).
26-31: Add unit tests to guard the new parents semanticsWe should assert that:
state.parentsis not mutated in-place after execution.- New states created for
outputs[1:]haveparentsequal to the original mapping, without any added self entry.I can draft tests mirroring
test_executed_state_empty_outputsto validate these invariants. Want me to open a testing PR or push commits to this one?Also applies to: 34-39, 41-53
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
state-manager/app/controller/executed_state.py(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
state-manager/app/controller/executed_state.py (1)
state-manager/tests/unit/controller/test_executed_state.py (1)
test_executed_state_empty_outputs(203-239)
🔇 Additional comments (2)
state-manager/app/controller/executed_state.py (2)
26-39: LGTM: self-parent augmentation removed on existing state pathsConfirmed we no longer augment
state.parentsin either path (empty outputs vs. first output). This aligns with the PR objective to stop self-referential parent entries.
41-53: Downstream parents logic verified safe
I confirmed instate-manager/app/tasks/create_next_state.py(around lines 62–68 and 109–115) that:
- The code explicitly skips
state.identifierwhen iterating dependencies.- All lookups against
state.parentstarget only other node identifiers (dependencies/inputs).No downstream logic expects the current state’s own ID in
parents. This change is safe.
@nk-ag this will fix the issue you are facing (: